<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>不同整数的最少数目</title>
</head>
<body>
  <script>
    function fn(arr, k) {
      let obj = {}
      arr.forEach((item) => {
        if (obj[item]) {
          obj[item] += 1
        } else {
          obj[item] = 1
        }
      })
      arr.sort((a, b) => {
        return obj[a] - obj[b] || a - b
      })
      arr.splice(0, k)
      return Array.from(new Set(arr)).length
    }
    console.log(fn([5, 5, 4], 1))
  </script>
</body>
</html>